package com.ibiaoke.goods.service;

import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.exception.ServiceException;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.goods.dao.GoodsClassDao;
import com.ibiaoke.goods.entity.Goods;
import com.ibiaoke.goods.entity.GoodsClass;
import com.ibiaoke.goods.entity.GoodsClassExample;
import com.ibiaoke.goods.entity.GoodsExample;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/6/7.
 */
@Service("goodsClassService")
public class GoodsClassServiceImpl implements GoodsClassService{
    @Autowired
    private GoodsClassDao goodsClassDao;

    /**
     * 商品分类
     * @return
     */
    @Override
    public List<GoodsClass> listGoodsClass() {
        List<GoodsClass> listGoodClass = goodsClassDao.listGoodsClass();
        return listGoodClass;
    }

    @Override
    public int saveGoodsClass(GoodsClass goodsClass) {

        AssertUtils.notBlank(goodsClass.getGcName(),"分类名称不能为空");

        AssertUtils.notNull(goodsClass.getGcParentId(),"父类Id不能为空");

        AssertUtils.notNull(goodsClass.getGcSort(),"排序不能为空");

        AssertUtils.notNull(goodsClass.getLevel(),"楼层不能为空");

        goodsClass.setDelStatus((byte) CommonConsts.NO);
        goodsClass.setCeateTime(new Date());
        goodsClass.setUpdateTime(new Date());

        return goodsClassDao.insertSelective(goodsClass);
    }
    @Override
    public int updateByGoodsClassId(GoodsClass goodsClass){

        AssertUtils.notNull(goodsClass.getGcId(),"分类Id不能为空");

        return goodsClassDao.updateByPrimaryKeySelective(goodsClass);
    }

    @Override
    public int deleteByGoodsClassId(Integer goodsClassId){

        AssertUtils.notNull(goodsClassId,"分类Id不能为空");

        return goodsClassDao.deleteByGoodsClassId(goodsClassId);
    }
}
